﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Luna.Framework.Impl;
using Luna;

namespace TextDataExtractor.DEML {
	public class ExecutionContext : DefaultContext {

		private DataBag storage = new DataBag() { Name = "Root"};

		public ExecutionContext(IAppContext parent, string name): base(parent, name) {
		}

		public AbstractPattern ActivePattern { get; set; }

		public DataBag Storage { get { return storage; } }

		public IDataStorage getVariable(string name) {
			return (IDataStorage) this[name];
		}

		public void setVariable(string name, DataBag var) {
			this[name] = var;
		}

		public IList<IDataStorage> getClassStorage(string className) {
			IList<IDataStorage> clazzStorage = (List<IDataStorage>)Storage[className];
			if (clazzStorage == null)
				Storage[className] = clazzStorage = new List<IDataStorage>();
			return clazzStorage;
		}

		public IEnumerable<IDataStorage> enumerateObject(string className) {
			IList<IDataStorage> clazzStorage = getClassStorage(className);
			foreach(IDataStorage obj in clazzStorage)
				yield return obj;
		}

		public void clear() {
			storage.Clear();
			base.clearProperties();
		}
	}
}
